regularize_party = function(str){
	str = tolower(str)
	if(grepl("scottish nation", str) | grepl("snp", str)){
		"snp"
	}else if(grepl("ukip", str) | grepl("kingdom indep", str)){
		"ukip"
	}else if(grepl("plaid", str)){
		"pc"
	}else if(grepl("labour", str)){
		"lab"
	}else if(grepl("conservative", str)){
		"con"
	}else if(grepl("liberal", str)){
		"ld"
	}else if(grepl("green", str)){
		"grn"
	}else if(grepl("bnp", str)){
		"bnp"
	}else{
		NA
	}
}


regularize_party_vec = function(source_vec, target_vec = NULL){
	if(is.null(target_vec)){target_vec = rep(NA, length(source_vec))} 
	source_vec = tolower(source_vec)
	key.mat = rbind(
		c("scottish nation", "snp"),
		c("ukip", "ukip"),	
		c("kingdom indep", "ukip"),
		c("plaid", "pc"),
		c("labour", "lab"),
		c("conservative", "con"),
		c("liberal", "ld"),
		c("green", "grn"),
		c("bnp", "bnp"),
		c("british national", "bnp"),
		c("none", "none"),
		c("know", "don't know"),
		c("other", "other")
		)
	for(j in 1:nrow(key.mat)){
		target_vec[grepl(key.mat[j,1], source_vec)] = key.mat[j,2]
	}	
	target_vec
}